package com.tlias.AOP;

import com.tlias.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Slf4j
@Component
@Aspect
public class MyAspectSSS {
    @Pointcut("execution(* com.tlias.service.impl.*.*(..))")
    public void pointcut(){}
    @Before("pointcut()")
    public void test(JoinPoint joinPoint){//获取方法参数
        //  获取方法参数
        //1.获取目标类名
        String name = joinPoint.getTarget().getClass().getName();
        //2.获取方法名
        String methodName = joinPoint.getSignature().getName();
        System.out.println("方法名"+methodName);
        //3.获取目标方法签名
        Signature signature = joinPoint.getSignature();
        System.out.println("方法签名"+signature);
        //4.获取方法参数
        Object[] args = joinPoint.getArgs();
        System.out.println("方法参数"+ Arrays.toString(args));
    }
    @Around("pointcut()")
    public Object  test(ProceedingJoinPoint joinPoint) throws Throwable{
        //  获取方法参数
        //1.获取目标类名
        String name = joinPoint.getTarget().getClass().getName();
        System.out.println("目标类名"+name);
        //2.获取方法名
        String methodName = joinPoint.getSignature().getName();
        System.out.println("方法名"+methodName);
        //3.获取目标方法签名
        Signature signature = joinPoint.getSignature();
        System.out.println("方法签名"+signature);
        //4.获取方法参数
        Object[] args = joinPoint.getArgs();
        System.out.println("方法参数"+ Arrays.toString(args));
        //5.获取方法返回值
        Object result = joinPoint.proceed();
        System.out.println("方法返回值"+result);
        return result;
    }
}
